package org.sgroup.imenu.controladapter;

import java.util.List;

import org.sgroup.imenu.IMenuActivity;
import org.sgroup.imenu.ListItemView;
import org.sgroup.imenu.R;
import org.sgroup.imenu.bo.Category;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ITabsFragment extends Fragment {
	private List<Category> categories = null;
	private Context context;

	public static Fragment newInstance(String title) {
		ITabsFragment f = new ITabsFragment();
		Bundle args = new Bundle();
		args.putString("title", title);
		f.setArguments(args);
		return f;
	}

	public ITabsFragment() {

	}

	public ITabsFragment(List<Category> cats, Context context) {
		// ITabsFragment f = new ITabsFragment();
		this.context = context;
		// Bundle args = new Bundle();
		// args.putInt(key, value)("position", position);
		// f.setArguments(args);
		this.categories = cats;
		// .return f;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		ViewGroup root = (ViewGroup) inflater.inflate(R.layout.itab_content,
				null);
		// final String title = getArguments().getString("title");
		ListView v = (ListView) root.findViewById(R.id.listItem);
		CategoriesListAdapter adapter = new CategoriesListAdapter(this.context,
				R.layout.list_category, categories);
		v.setAdapter(adapter);

		// phantsang@gmail.com
		v.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adView, View target,
					int position, long id) {
				Category cat = categories.get(position);
				ListItemView newView = new ListItemView(context, cat);
				((IMenuActivity) context).ChangeView(newView, false);
			}
		});

		return root;
	}

}
